﻿<%@ Page Language="C#" MasterPageFile="~/Areas/admin/Views/Shared/List.Master" Inherits="System.Web.Mvc.ViewPage<Longtop.Web.SaleWeb.Admin.Excel.CreateModel>" %>

<asp:Content ContentPlaceHolderID="Pager" runat="server">
    <link href="../../../../Scripts/jquery-datepicker/css/ui-lightness/jquery-ui-1.7.2.custom.css"
        rel="stylesheet" type="text/css" />

    <script src="../../../../Scripts/jquery-datepicker/js/jquery-ui-1.7.2.custom.min.js"
        type="text/javascript"></script>

    <link href="../../../../Scripts/jquery-autocomplete/jquery.autocomplete.css" rel="stylesheet"
        type="text/css" />

    <script src="../../../../Scripts/jquery-autocomplete/jquery.autocomplete.pack.js"
        type="text/javascript"></script>

    <link href="../../../../Scripts/jquery-simplemodal/demos.css" rel="stylesheet" type="text/css" />

    <script src="../../../../Scripts/jquery.maskMoney.0.2.js" type="text/javascript"></script>

    <script src="../../../../Scripts/jquery-simplemodal/jquery.simplemodal-1.3.4.min.js"
        type="text/javascript"></script>

    <style type="text/css">
        #ui-datepicker-div
        {
            z-index: 9999999;
        }
    </style>

    <script type="text/javascript">
        $(
        function() {
            var data = '<%=Lable.GetAllDepartments().SelectMany(p => { return new[] {new KeyValuePair<int,string>(p.LableId,p.Text) }; }).ToJson()%>';
            data = eval(data);
            var options = {
                minChars: 0,
                max: 20,
                autoFill: false,
                mustMatch: true,
                matchContains: true,
                scrollHeight: 220,
                formatItem: function(row, i, total) {
                    // don't show the current month in the list of values (for whatever reason)
                    return row.Value;
                }
            };

            var click = function() {
                var tr = $(this).parents('tr:first');
                var datepicker = tr.find('input[rel^="datepicker"]');
                var username = tr.find('input[name$="UserName"]');
                var department = tr.find('input[name$="Text"]');

                $.modal(tr, { persist: true,
                    onShow: function(d) {
                        d = d.data;
                        d.find('a').hide();
                        options.formatResult = function(row) {
                            return row.Key
                        };
                        username.autocomplete([], options)
                        options.formatResult = function(row) {
                            return row.Value
                        };

                        datepicker.datepicker({ defaultDate: 0,
                            duration: 'fast', showAnim: ''
                        });
                        department.autocomplete(data, options)
                        .result(function(event, row, formatted) {
                            if (row) {
                                var sale = d.find('input[name$="UserName"]');
                                sale.attr('disabled', 'disabled').val('...');
                                $.getJSON('<%=Url.Action("getsales","sales") %>/' + row.Key, function(data) {
                                    sale.removeAttr('disabled').val('').flushCache().setOptions({ data: data });
                                });
                            }
                            //return formatted
                        });
                        var row = $(data).map(
                        function(i, item) {
                            if (item.Value == department.val())
                                return item
                        });
                        if (row.size() > 0)
                            department.trigger('result', [row[0], row[0].Value]);
                        d.find('input.money').maskMoney({ symbol: '￥', thousands: '' });
                        d.find('input.percent').maskMoney({ symbol: '', thousands: '' });
                        d.find('input.input-validation-error').removeAttr('title');
                        d.after($('<tr><td colspan="20"><input type="button" value="确认" onclick="$.modal.close();" /></td></tr>'));
                    },
                    onClose: function(d) {
                        d = d.data;
                        d.find('a').show();
                        datepicker.datepicker('destroy');
                        department.unautocomplete();
                        username.unautocomplete();
                        d.find('input').not(datepicker).unbind();
                        d.find('input.input-validation-error').click(click).attr('title', '单击解决该问题');
                        $.modal.close();
                    }
                });
            }
            $('.edit,input[class$="error"]').click(click).not('.edit').attr('title', function() {
                return '单击解决问题'

                //$(this).parent().find('span').text();
            });


        });
    </script>

</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <thead>
        <tr>
            <th>
                部门
            </th>
            <th>
                <%=Html.LabelFor(m=>m.Model.First().Sale.UserName) %>
            </th>
            <th>
                日期
            </th>
            <th>
                <%=Html.LabelFor(m=>m.Model.First().ProductName) %>
            </th>
            <th>
                年限
            </th>
            <th>
                合同金额
            </th>
            <th>
                本期到款
            </th>
            <th>
                本期前累积到款
            </th>
            <th>
                未到款项
            </th>
            <th>
                单价
            </th>
            <th>
                折扣
            </th>
            <th>
                折标系数
            </th>
            <th>
                折标业绩
            </th>
            <%-- <th>
                操作
            </th>--%>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="10">
                <%=Html.SubmitButton("", "导入", new { Class = "button" }) %>
                <%=Html.ValidationSummary(true) %>
                <%=Model.OperateMessage %>

                <script type="text/javascript">
                    $(function() {
                        $('input:submit').click(
                        function() {
                            $(this).parents('form').attr('action', '<%=Url.Action("import") %>');
                        }
                        );
                    });
                </script>

            </td>
        </tr>
        <%for (int i = 0; i < Model.Model.Count; i++) {
              if (Model.SuccessModel.Contains(Model.Model[i]))
                  continue;
        %>
        <tr>
            <td>
                <%= Html.TextBoxFor(m => m.Model[i].Department.Text)%>
                <%=Html.ValidationMessageFor(m => m.Model[i].Department.Text)%>
            </td>
            <td>
                <%= Html.TextBoxFor(m => m.Model[i].Sale.UserName)%>
                <%=Html.ValidationMessageFor(m => m.Model[i].Sale.UserName)%>
            </td>
            <td>
                <%= Html.TextBoxFor(m => m.Model[i].CreateDT, new { rel = "datepicker" })%>
                <%=Html.ValidationMessageFor(m => m.Model[i].CreateDT)%>
            </td>
            <td>
                <%= Html.TextBoxFor(m=>m.Model[i].ProductName) %>
                <%=Html.ValidationMessageFor(m => m.Model[i].ProductName)%>
            </td>
            <td>
                <%= Html.TextBoxFor(m => m.Model[i].Years, new { Class = "years",maxlength=2})%>
                <%=Html.ValidationMessageFor(m => m.Model[i].Years)%>
            </td>
            <td>
                <%= Html.TextBoxFor(m => m.Model[i].Amount, new { Class = "money" })%>
                <%=Html.ValidationMessageFor(m=>m.Model[i].Amount) %>
            </td>
            <td>
                <%= Html.TextBoxFor(m=>m.Model[i].Reached, new { Class = "money" }) %>
                <%=Html.ValidationMessageFor(m => m.Model[i].Reached)%>
            </td>
            <td>
                <%= Html.TextBoxFor(m=>m.Model[i].ReachedCount, new { Class = "money" }) %>
                <%=Html.ValidationMessageFor(m => m.Model[i].ReachedCount)%>
            </td>
            <td>
                <%= Html.TextBoxFor(m=>m.Model[i].NoReached, new { Class = "money" }) %>
                <%=Html.ValidationMessageFor(m => m.Model[i].NoReached)%>
            </td>
            <td>
                <%= Html.TextBoxFor(m => m.Model[i].Price, new { Class = "money" })%>
                <%=Html.ValidationMessageFor(m => m.Model[i].Price)%>
            </td>
            <td>
                <%= Html.TextBoxFor(m => m.Model[i].Discount, new { Class = "percent" })%>
                <%=Html.ValidationMessageFor(m => m.Model[i].Discount)%>
            </td>
            <td>
                <%= Html.TextBoxFor(m => m.Model[i].SaleDiscount, new { Class = "percent" })%>
                <%=Html.ValidationMessageFor(m => m.Model[i].SaleDiscount)%>
            </td>
            <td>
                <%= Html.TextBoxFor(m => m.Model[i].SaleAchievement, new { Class = "money" })%>
                <%=Html.ValidationMessageFor(m => m.Model[i].SaleAchievement)%>
            </td>
            <td>
                <%if (ViewData.ModelState.Any(x => x.Key.StartsWith("[" + i + "]") && x.Value.Errors.Count > 0)) {%>
                <a href="javascript:void(0);" class="edit">修正</a>
                <%} %>
                <%--  <%= Html.ActionLink("编辑", "Edit", new {  id=item.Id}) %>--%>
                <%--  |<%= Html.ActionLink("删除", "Delete", new {  id=item.CaseId}) %>--%>
            </td>
        </tr>
        <% } %>
    </tbody>
</asp:Content>
